package Reminder.view.pages;

import Reminder.dao.RemindDao;
import Reminder.dao.impl.RemindDaoImpl;
import Reminder.domain.Message;
import com.alibaba.fastjson.JSONObject;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDatePicker;
import com.jfoenix.controls.JFXTextField;
import com.jfoenix.controls.JFXTimePicker;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import Reminder.view.Controller;
import Reminder.view.GlobalConfig;
import Reminder.view.Main;

import java.awt.*;
import java.io.IOException;
import java.text.ParseException;
import java.util.Optional;

public class pageIndex extends Page {
    Scene scene;
    Controller controller;
    public pageIndex(Stage stage, Controller controller) {
        super(stage,controller);
        BorderPane root = new BorderPane();
        root.getStyleClass().add("root");

        Image icon = new Image("/img/SakanaCatcher.png");
        BorderPane logoPane = new BorderPane();
        ImageView imageView = new ImageView();


        imageView.setFitHeight(410);
        imageView.setFitWidth(800);
        imageView.setImage(icon);
        logoPane.setCenter(imageView);

        Rectangle clip = new Rectangle(imageView.getFitWidth(), imageView.getFitHeight());
        clip.setArcWidth(100);
        clip.setArcHeight(100);
        imageView.setClip(clip);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage image = imageView.snapshot(parameters, null);
        imageView.setClip(null);
        imageView.setImage(image);




        Label appName = new Label(GlobalConfig.APP_NAME);
        appName.getStyleClass().add("appName");
        logoPane.setBottom(appName);


        logoPane.setPrefSize(  Math.round(GlobalConfig.WINDOW_WIDTH / 5.) +400, Math.round(GlobalConfig.WINDOW_HEIGHT / 5.) + 400);
        BorderPane.setAlignment(logoPane, Pos.CENTER);
        BorderPane.setAlignment(appName, Pos.CENTER);
        root.setTop(logoPane);

        HBox hBox = new HBox();
        JFXButton login = new JFXButton("登  录");
        login.getStyleClass().add("login");
        login.setPrefSize(250,GlobalConfig.PRIMARY_BUTTON_HEIGHT);
        login.setOnMouseClicked(
                new EventHandler<MouseEvent>() {

                    @Override
                    public void handle(MouseEvent mouseEvent) {
                        GlobalConfig.WINDOW_CURRENT_WIDTH = getStage().getScene().getWidth();
                        GlobalConfig.WINDOW_CURRENT_HEIGHT = getStage().getScene().getHeight();
//                        getStage().hide();

                        pageLogin pageLogin = new pageLogin(getStage(),getController());
//                        getStage().show();
//                        l2.showPage();
                    }
                }
        );

        JFXButton offLine = new JFXButton("离线模式");
        offLine.setPrefSize(250,GlobalConfig.PRIMARY_BUTTON_HEIGHT);
        offLine.getStyleClass().add("offLine");
        offLine.setOnMouseClicked(
                new EventHandler<MouseEvent>() {

                    @Override
                    public void handle(MouseEvent mouseEvent) {
                        GlobalConfig.WINDOW_CURRENT_WIDTH = getStage().getScene().getWidth();
                        GlobalConfig.WINDOW_CURRENT_HEIGHT = getStage().getScene().getHeight();
                        try {
                            GlobalConfig.IS_LOGIN = false;
                            pageOptions pageOptions = new pageOptions(getStage(),getController());
                        } catch (IOException | ParseException | AWTException e) {
                            e.printStackTrace();
                        }
                    }
                }
        );

        hBox.setSpacing(80);
        hBox.setPrefHeight(200);
        hBox.getChildren().addAll(login,offLine);
        hBox.setAlignment(Pos.CENTER);
        root.setCenter(hBox);
//        RemindCell reminderCell = new RemindCell("标题","内容内容内容内容内容内容内容内容内容内容内容内容内容内容",new Date());
        System.out.println(getStage().getWidth());
//        root.setBottom(reminderCell);
        Scene scene = new Scene(root,GlobalConfig.WINDOW_CURRENT_WIDTH, GlobalConfig.WINDOW_CURRENT_HEIGHT);
        scene.getStylesheets().add(Main.class.getResource("/css/index.css").toExternalForm());

        stage.setScene(scene);

    }


}
